﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataCom;
using System.Data;
using System.Xml;
using XmlDataCommunication.Properties;

namespace XmlDataCommunication
{
    public class XmlLineNameDataAccess : ILineNameAccess
    {
        public DataTable GetAllLineName()
        {
            XmlDocument doc = GeneralFunctions.GetXmlDocument();
            XmlNodeList nodes = doc.SelectNodes("//LINE_NAME/Record");
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("Line_Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Line_Code", typeof(string)));
            dt.Columns.Add(new DataColumn("JIBU", typeof(string)));
            dt.Columns.Add(new DataColumn("JIBU_Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Serial_Port", typeof(string)));

            foreach (XmlNode item in nodes)
            {
                DataRow row = dt.NewRow();
                row["Line_Name"] = item.SelectSingleNode("./Line_Name").InnerText;
                row["Line_Code"] = item.SelectSingleNode("./Line_Code").InnerText;
                row["JIBU"] = item.SelectSingleNode("./JIBU").InnerText;
                row["JIBU_Name"] = item.SelectSingleNode("./JIBU_Name").InnerText;
                row["Serial_Port"] = item.SelectSingleNode("./Serial_Port").InnerText;
                dt.Rows.Add(row);
            }
            return dt;
        }
    }
}
